home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-08-04 | 3.4 KB | 155 lines | [TEXT/PJMM] |
- unit MyLogWindow;
-
- interface
-
- const
- rows = 100;
-
- var
- log_window: windowPtr;
- hide_log_window_in_background: boolean;
-
- procedure InitLogWindow;
- procedure ShowLogWindow;
- procedure FinishLogWindow;
- function HandleLogWindowEvents (var er: eventRecord): boolean;
- procedure LogToWindow (s: str255);
- { returns true if we handle it }
- { You can safely call HandleLogWindowEvents and LogToWindow even if InitLogWindow is not called, it will bounce,}
- { since log_window defaults to nil }
-
- implementation
-
- uses
- MyTypes;
-
- var
- lh: listHandle;
-
- procedure LogToWindow (s: str255);
- var
- c: cell;
- begin
- if log_window <> nil then begin
- if lh^^.dataBounds.bottom >= rows then
- LDelRow(1, 0, lh);
- c.v := LAddRow(1, lh^^.dataBounds.bottom, lh);
- c.h := 0;
- LSetCell(@s[1], length(s), c, lh);
- LScroll(0, rows, lh);
- end;
- end;
-
- procedure InitLogWindow;
- var
- view, bounds: rect;
- size: point;
- begin
- SetRect(view, 10, 40, 500, 40 + 16 * 14);
- log_window := NewWindow(nil, view, 'Log Window', false, noGrowDocProc, POINTER(-1), false, 0);
- SetPort(log_window);
- SetRect(bounds, 0, 0, 1, 0);
- OffsetRect(view, -view.left, -view.top);
- view.right := view.right - 15;
- Setpt(size, 0, 0);
- lh := LNew(view, bounds, size, 0, log_window, false, false, false, true);
- end;
-
- procedure ShowLogWindow;
- begin
- if log_window <> nil then begin
- LDoDraw(true, lh);
- ShowWindow(log_window);
- end;
- end;
-
- procedure FinishLogWindow;
- begin
- if log_window <> nil then begin
- LDispose(lh);
- DisposeWindow(log_window);
- end;
- end;
-
- function HandleLogWindowEvents (var er: eventRecord): boolean;
- procedure DoDrag (where: point);
- var
- temprect: rect;
- bnds1, bnds2: point;
- begin
- temprect := GetGrayRgn^^.rgnBBox;
- bnds1 := log_window^.portBits.bounds.topleft;
- DragWindow(log_window, where, temprect);
- bnds2 := log_window^.portBits.bounds.topleft;
- end;
- var
- twp: windowPtr;
- code: integer;
- dummy, didit: boolean;
- begin
- didit := false;
- if log_window <> nil then begin
- case er.what of
- MouseDown: begin
- code := FindWindow(er.where, twp);
- if (twp <> nil) & (twp = log_window) then begin
- SetPort(log_window);
- if (FrontWindow <> log_window) then begin
- if (BAND(er.modifiers, cmdKey) = 0) or (code <> inDrag) then
- SelectWindow(log_window);
- if code = inDrag then
- DoDrag(er.where);
- didit := true;
- end
- else
- case code of
- InDrag: begin
- DoDrag(er.where);
- didit := true;
- end;
- inContent, inGrow: begin
- GlobalToLocal(er.where);
- dummy := LClick(er.where, er.modifiers, lh);
- didit := true;
- end;
- otherwise
- ;
- end;
- end;
- end;
-
- keyDown, autoKey:
- ;
-
- UpdateEvt:
- if windowPtr(er.message) = log_window then begin
- BeginUpdate(log_window);
- LUpdate(log_window^.visRgn, lh);
- EndUpdate(log_window);
- didit := true;
- end;
-
- kOSEvent: begin
- if BAND(BROTL(er.message, 8), $FF) = kSuspendResumeMessage then begin
- if BAnd(er.message, kResumeMask) <> 0 then
- ShowWindow(log_window)
- else if hide_log_window_in_background then
- HideWindow(log_window);
- InitCursor;
- end;
- end;
-
- ActivateEvt: begin
- if windowPtr(er.message) = log_window then begin
- LActivate(odd(er.modifiers), lh);
- didit := true;
- end;
- end;
-
- otherwise
- end;
- end;
- HandleLogWindowEvents := didit;
- end;
-
- end.